package com.itheima.service.impl;

import com.itheima.mapper.EmpMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.PageBean;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public Emp selectId(Integer id) {
        Emp emp= empMapper.selectId(id);
        return emp;
    }

    @Override
    public PageBean page(Integer page, Integer pageSize,String name, Short gender, LocalDate begin, LocalDate end) {
        //获取总记录数
        Long count= empMapper.count(name,gender,begin,end);
        //获取数据
        Integer start=(page-1)*pageSize;
        List<Emp> empList=empMapper.page(start,pageSize,name,gender,begin,end);
        //封装对象
        PageBean pageBean=new PageBean(empList,count);
        return pageBean;
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void addEmp(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.addEmp(emp);
    }

    @Override
    public void updata(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.updata(emp);
    }

    /**
     * 登录请求
     * @param emp
     * @return
     */
    @Override
    public Emp login(Emp emp) {

        Emp e=empMapper.login(emp);
        return e;
    }



}
